package com.weigee.ktv.v.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.l.d.app.library.util.ResourceUtil;
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.weigee.ktv.R;
import com.weigee.ktv.m.util.RefreshUtil;
import com.weigee.ktv.v.adapter.rv.RoomReservationAdapter;
import com.weigee.ktv.v.view.WrapTitleBar;

import butterknife.BindView;

/**
 * Created by 林德 on 2017/4/17 11:34.
 * <p/>
 */
public class RoomReservationListFragment extends BaseFragment implements View.OnClickListener
{
    @BindView(R.id.wrap_title_bar)
    WrapTitleBar mTitleBar;
    @BindView(R.id.t_refresh)
    TwinklingRefreshLayout m_tRefresh;
    @BindView(R.id.recycler_view)
    RecyclerView mRv;

    private RoomReservationAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.recycler_wrap, container, false);
    }

    @Override
    protected void initView(View view, @Nullable Bundle savedInstanceState)
    {
        final Context context = view.getContext();
        mTitleBar.setTitle(ResourceUtil.string(context, R.string.title_room_reservation));
        mTitleBar.setLeftButton(View.VISIBLE,this);

        RefreshUtil.initTwinklingRefresh(m_tRefresh, new RefreshListenerAdapter()
        {
            @Override
            public void onRefresh(TwinklingRefreshLayout refreshLayout)
            {
                super.onRefresh(refreshLayout);
                m_tRefresh.finishRefreshing();
            }

            @Override
            public void onLoadMore(TwinklingRefreshLayout refreshLayout)
            {
                super.onLoadMore(refreshLayout);
                m_tRefresh.finishLoadmore();
            }
        });
        initRv(context);
    }

    private void initRv(Context context)
    {
        LinearLayoutManager llm = new LinearLayoutManager(context);
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        mRv.setLayoutManager(llm);

        mAdapter = new RoomReservationAdapter();
        mRv.setAdapter(mAdapter);
    }

    @Override
    public void onClick(View v)
    {
        back();
    }
}
